﻿@{
    Layout = null;
}
<!DOCTYPE html>
<html lang="ch">
<head>
    <meta name="viewport" content="width=device-width" />
    <title>Login</title>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <meta charset="utf-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <link href="/Content/plugins/bootstrap/css/bootstrap.min.css" rel="stylesheet" type="text/css" />
    <!--[if lte IE 6]>
       <link rel="stylesheet" type="text/css" href="/Content/themes/bootstrap-ie/css/bootstrap-ie6.css" />
       <link rel="stylesheet" type="text/css" href="/Content/themes/bootstrap-ie/css/ie.css" />
    <![endif]-->
    <link href="/Content/plugins/font-awesome/css/font-awesome.min.css" rel="stylesheet"
        type="text/css" />
    <link href="/Content/css/ace.min.css" rel="stylesheet" type="text/css" />
    <!--[if lte IE 8]>
	    <link rel="stylesheet" type="text/css"  href="/Content/ace-ie.min.css" />
        <link href="/Content/themes/font-awesome/css/font-awesome-ie7.min.css" rel="stylesheet"
            type="text/css" />
	<![endif]-->
    <!--[if lt IE 9]>
		<script rel="stylesheet" type="text/css" src="/scripts/html5shiv.js"></script>
		<script rel="stylesheet" type="text/css" src="/scripts/respond.min.js"></script>
	<![endif]-->
    <link href="/Content/css/custom.css" rel="stylesheet" type="text/css" />
</head>
<body class="login-layout" onload="InitDiv()" onresize="InitDiv()">
    <input type="hidden" name="token" id="token" />
    <div class="main-container">
        <div class="main-content">
            <div class="row">
                <div class="col-sm-10 col-sm-offset-1">
                    <div class="login-container" id="loginformDiv">
                        <div class="position-relative" id="logindiv">
                            <div id="login-box" class="login-box visible widget-box no-border">
                                <div class="widget-body">
                                    <div class="widget-main">
                                        <h4 class="header blue lighter bigger">
                                            <i class="icon-coffee green"></i>融汇贷后台管理中心
                                        </h4>
                                        <div class="space-6">
                                        </div>
                                        <form id="loginform" action="/">
                                        <table border="0" width="270">
                                            <tr>
                                                <td colspan="2">
                                                    <label class="block clearfix">
                                                        <span class="block input-icon input-icon-left">
                                                            <input type="text" id="txtUsername" name="txtUsername" class="{required:true}" style="width: 270px;
                                                                background-color: #fff;" placeholder="用户名" />
                                                            <i class="icon-user"></i></span>
                                                    </label>
                                                </td>
                                            </tr>
                                            <tr>
                                                <td colspan="2">
                                                    <label class="block clearfix">
                                                        <span class="block input-icon input-icon-left">
                                                            <input type="password" id="txtPassword" name="txtPassword" class="{required:true}"
                                                                style="width: 270px; background-color: #fff;" placeholder="密码" />
                                                            <i class="icon-lock"></i></span>
                                                    </label>
                                                </td>
                                            </tr>
                                            <tr>
                                                <td width="135">
                                                    <label class="block clearfix">
                                                        <span class="block input-icon input-icon-left">
                                                            <input type="text" class="form-control" id="txtCheckcode" name="txtCheckcode" style="width: 135px;
                                                                background-color: #fff;" placeholder="验证码" />
                                                            <i class="icon-barcode"></i></span>
                                                    </label>
                                                </td>
                                                <td valign="top">
                                                    <div id="codeimg" style="margin-top: 0px; display: inline;">
                                                    </div>
                                                </td>
                                            </tr>
                                            <tr>
                                                <td colspan="2" valign="top">
                                                    <span id="lblmsg" style="color: Red">&nbsp;</span>
                                                </td>
                                            </tr>
                                            <tr>
                                                <td colspan="2">
                                                    <button class="btn btn-block btn-primary" id="btnLogin" type="button" data-loading-text="Loading...">
                                                        登录</button>
                                                </td>
                                            </tr>
                                        </table>
                                        </form>
                                        <form id="checkform" style="display: none" action="/">
                                        <table border="0" width="270">
                                            <tr>
                                                <td width="70" valign="middle" align="right">
                                                    <h4 class="blue lighter smaller">
                                                        手机号:</h4>
                                                </td>
                                                <td valign="top" align="left">
                                                    <label class="block clearfix">
                                                        <h3 class="header black lighter smaller" id="hPhoneNum">
                                                        </h3>
                                                    </label>
                                                </td>
                                            </tr>
                                            <tr>
                                                <td valign="top" align="right">
                                                    <h4 class="blue lighter smaller">
                                                        验证码:</h4>
                                                </td>
                                                <td valign="top" align="left">
                                                    <label class="block clearfix">
                                                        <span class="block">
                                                            <input type="text" id="txtPhoneCheck" name="txtPhoneCheck" class="{required:true,messages:{required:'不能为空'}}"
                                                                style="width: 170px; background-color: #fff;" placeholder="6位手机验证码" />
                                                        </span>
                                                    </label>
                                                </td>
                                            </tr>
                                            <tr>
                                                <td colspan="2" valign="middle">
                                                    <span id="lblmsgtemp" style="color: Red">&nbsp;</span>
                                                </td>
                                            </tr>
                                            <tr>
                                                <td colspan="2">
                                                    <button class="btn btn-block btn-primary" id="btnCheck" type="button">
                                                        验证</button>
                                                </td>
                                            </tr>
                                        </table>
                                        </form>
                                        <div class="space-4">
                                        </div>
                                    </div>
                                    <!-- /widget-body -->
                                </div>
                                <!-- /login-box -->
                            </div>
                            <!-- /position-relative -->
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </div>
    <!-- /.main-container -->
    <script src="/Content/scripts/jquery-1.10.2.min.js" type="text/javascript"></script>
    <script src="/Content/plugins/bootstrap/js/bootstrap.min.js" type="text/javascript"></script>
    <!--[if lte IE 6]>>
      <script type="text/javascript" src="/Content/themes/bootstrap-ie/js/bootstrap-ie.js"></script>
    <![endif]-->
    <script src="/Content/plugins/bootbox.min.js" type="text/javascript"></script>
    <script type="text/javascript" src="/Content/scripts/library.js"></script>
    <script type="text/javascript" src="/Content/scripts/jquery-validate/jquery.validate.js"></script>
    <script type="text/javascript" src="/Content/scripts/jquery-validate/jquery.metadata.js"></script>
    <script type="text/javascript" src="/Content/scripts/plug.js"></script>
    <script type="text/javascript">
        var validation = new plug.BindValidCode();
        $(function () {
            validation.BindValidator();
            $('#loginform').validate({
                errorClass: "help-inline",
                errorElement: "span",
                highlight: function (element, errorClass, validClass) {
                    $(element).parents('.control-group').addClass('error');
                },
                unhighlight: function (element, errorClass, validClass) {
                    $(element).parents('.control-group').removeClass('error');
                }
            });

            $('#checkform').validate({
                errorClass: "help-inline",
                errorElement: "span",
                highlight: function (element, errorClass, validClass) {
                    $(element).parents('.control-group').addClass('error');
                },
                unhighlight: function (element, errorClass, validClass) {
                    $(element).parents('.control-group').removeClass('error');
                }
            });
        });
        function Refalsh(sender) {
            validation.Refalsh(sender);
        }
    </script>
    <script type="text/javascript">
        function InitDiv() {
            var logindiv = $("#login-box");
            logindiv.css("margin-top", $(window).height() / 2 - logindiv.height() / 2);

        }
    </script>
    <script type="text/javascript">
        var loading;
        $(function () {
            $(".login-text").focus(function () {
                $(this).addClass("login-text-focus");
            }).blur(function () {
                $(this).removeClass("login-text-focus");
            });

            $(document).keydown(function (e) {
                if (e.keyCode == 13) {
                    dologin();
                }
            });

            $("#btnLogin").click(function () {
                $("#btnLogin").text("登录中...");
                $("#btnLogin").attr("disabled", true);

                dologin();
            });
            

        $("#btnCheck").click(function () {
            $("#btnCheck").text("验证中...");
            $("#btnCheck").attr("disabled", true);

            doCheck();
        });
        $("#txtUsername").focus();  
        });

        function dologin() {
            //bootbox.alert("Hello world!");
                var username = $("#txtUsername").val();
                var password = $("#txtPassword").val();
                var validationCode = $("#txtCheckcode").val();
                if (username == "") {
                    // $.ligerDialog.warn('用户名不能为空！', '温馨提示');
                    $("#lblmsg").html("用户名不能为空！");
                    $("#btnLogin").text("登录");
                    $("#btnLogin").attr("disabled", false);
                    $("#txtUsername").focus();
                    return;
                }
                if (password == "") {
                    $("#lblmsg").html("密码不能为空！");
                    //$.ligerDialog.warn('密码不能为空！', '温馨提示');
                    $("#btnLogin").text("登录");
                    $("#btnLogin").attr("disabled", false);
                    $("#txtPassword").focus();
                    return;
                }
                if (validationCode == "") {
                    $("#lblmsg").html("验证码不能为空！");
                    //$.ligerDialog.warn('验证码不能为空！', '温馨提示');
                    $("#btnLogin").text("登录");
                    $("#btnLogin").attr("disabled", false);
                    $("#txtCheckcode").focus();
                    return;
                }

                $.ajax({
                    type: 'post',
                    cache: false,
                    url: '/account/login',
                    data: 'userName=' + username + '&password=' + password + '&validateCode=' + validationCode + '&token=' + $("#token").val(),
                    success: function (result) {
                        result = eval("(" + result + ")");
                        if (!result) {
                            $("#txtUsername").focus();
                            return;
                        }
                        else {
                            if (result.RID == "1") {
                                location.href = decodeURIComponent("/home/index");
                            }
                            else if (result.RID == "99") {
                                //location.href = decodeURIComponent("/home/index");
                                //弹出手机输入验证码输入框
                                $("#hPhoneNum").text(result.PHONE);
                                //$('#myModal').modal('toggle')
                                var logindiv = $("#loginform");
                                logindiv.css("display", "none");
                                var phonediv = $("#checkform");
                                phonediv.css("display", "inline");
                            }
                            else if (result.RID == "-9") {
                                // $.ligerDialog.warn('验证码错误！', '温馨提示');
                                $("#lblmsg").html("验证码输入错误！");
                                $("#btnLogin").text("登录");
                                $("#btnLogin").attr("disabled", false);
                                $("#checkcode").focus();
                            }
                            else if (result.RID == "-10") {
                                // $.ligerDialog.warn('验证码错误！', '温馨提示');
                                $("#lblmsg").html("系统错误，请联系管理员！");
                                $("#btnLogin").text("登录");
                                $("#btnLogin").attr("disabled", false);
                                $("#checkcode").focus();
                            }
                            else if (result.RID == "-1") {
                                //$.ligerDialog.warn('用户名不存在！', '温馨提示');
                                $("#lblmsg").html("用户名不存在！");
                                $("#btnLogin").text("登录");
                                $("#btnLogin").attr("disabled", false);
                                $("#txtUsername").focus();
                            }
                            else if (result.RID == "-2") {
                                // $.ligerDialog.warn('用户名已禁用，请联系管理员开通！', '温馨提示');
                                $("#lblmsg").html("该用户已禁用，请联系管理员开通！");
                                $("#btnLogin").text("登录");
                                $("#btnLogin").attr("disabled", false);
                                $("#txtUsername").focus();
                            }
                            else if (result.RID == "-3") {
                                //$.ligerDialog.warn('密码错误！', '温馨提示');
                                $("#lblmsg").html("密码错误！");
                                $("#btnLogin").text("登录");
                                $("#btnLogin").attr("disabled", false);
                                $("#txtPassword").focus();
                            }
                            else {
                                //$.ligerDialog.warn('未知错误，请联系管理员！', '温馨提示');
                                $("#lblmsg").html("未知错误，请联系管理员！");
                                $("#btnLogin").text("登录");
                                $("#btnLogin").attr("disabled", false);
                                $("#txtUsername").focus();
                            }
                        }
                    },
                    error: function () {
                        $("#lblmsg").html("系统错误,请与系统管理员联系!"); 
                    },
                    beforeSend: function () {
                        // $.ligerDialog.waitting("正在登录中,请稍后...");
                        $("#btnLogin").text("登录中...");
                        $("#btnLogin").attr("disabled", true);
                    },
                    complete: function () {
                        //$.ligerDialog.closeWaitting();
                        $("#btnLogin").text("登录");
                        $("#btnLogin").attr("disabled", false);
                    }
                });
            }
            function doCheck() {

                var userName = $("#txtUsername").val();
                var checkeCode = $("#txtPhoneCheck").val();
                if (checkeCode == "") {
                    $("#lblmsgtemp").html("验证码不能为空!");
                    $("#btnCheck").text("验证");
                    $("#btnCheck").attr("disabled", false);
                    $("#txtPhoneCheck").focus();
                    return;
                }
                $.ajax({
                    url: "Account/CheckShortMessageCode",
                    data: 'userName=' + userName + '&checkCode=' + checkeCode,
                    type: 'Post',
                    success: function (result) {
                        if (result == "1") {
                            location.href = decodeURIComponent("/home/index");
                            $("#txtPhoneCheck").val("");
                        }
                        else if (result=="0") {
                            $("#lblmsgtemp").html("验证码输入错误!");
                        }
                        else if (result == "-1") {
                            $("#lblmsgtemp").html("用户名错误!");
                        }
                    },
                    error: function () {
                        $("#lblmsgtemp").html("系统错误,请与系统管理员联系!");
                    },
                    beforeSend: function () {
                        // $.ligerDialog.waitting("正在登录中,请稍后...");
                        $("#btnCheck").text("验证中...");
                        $("#btnCheck").attr("disabled", true);
                    },
                    complete: function () { 
                        $("#btnCheck").text("验证");
                        $("#btnCheck").attr("disabled", false);
                    }
                });
            }
    </script>
</body>
</html>
